let g:plug_file_path = ""

if has("win32")
    let g:plug_file_path = "~/AppData/Local/nvim/plugged"
else
    let g:plug_file_path = "~/.config/nvim/plugged"
endif

call plug#begin(plug_file_path)
" Plug 'autozimu/LanguageClient-neovim', {
" \ 'branch': 'next',
" \ 'do': 'bash install.sh',
" \ }
" idea
" Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
" Plug 'beeender/Comrade'

" 文件树
"Plug 'nvim-tree/nvim-web-devicons' " optional
Plug 'nvim-tree/nvim-tree.lua'
"
" Plug 'joereynolds/gtags-scope'
Plug 'https://gitcode.net/BlueSky4_19/vimtex.git'
Plug 'https://gitcode.net/BlueSky4_19/vim-oscyank.git'
" 在浏览器中使用nvim
" Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } }
" " (Optional) Multi-entry selection UI.
" Plug 'junegunn/fzf'
" Plug 'easymotion/vim-easymotion'
Plug 'Lokaltog/vim-easymotion'
Plug 'https://gitcode.net/BlueSky4_19/vifm.vim'
" Plug 'Raimondi/delimitMate'
Plug 'jiangmiao/auto-pairs'
Plug 'https://gitcode.net/BlueSky4_19/vim-markbar.git'
Plug 'rbgrouleff/bclose.vim'
" Plug 'francoiscabrol/ranger.vim'
" Plug 'vim-scripts/fcitx.vim'
Plug 'vim-airline/vim-airline'
" Plug 'lyokha/vim-xkbswitch'

" Plug 'connorholyday/vim-snazzy'
Plug 'https://gitcode.net/BlueSky4_19/vim-snazzy.git'

Plug 'sickill/vim-monokai'
Plug 'phanviet/vim-monokai-pro'
" Plug 'https://gitcode.net/mirrors/scrooloose/nerdtree.git', { 'on': 'NERDTreeToggle' }
" Plug 'Xuyuanp/nerdtree-git-plugin'

" Taglist
Plug 'majutsushi/tagbar', { 'on': 'TagbarOpenAutoClose' }

" Error checking
"Plug 'w0rp/ale'

" Auto Complete
"Plug 'Valloric/YouCompleteMe'

" Undo Tree
"Plug 'mbbill/undotree/'

" Other visual enhancement
" Plug 'nathanaelkane/vim-indent-guides'
"Plug 'itchyny/vim-cursorword'

" Git
" Plug 'rhysd/conflict-marker.vim'
" Plug 'tpope/vim-fugitive'
" Plug 'mhinz/vim-signify'
" Plug 'gisphm/vim-gitignore', { 'for': ['gitignore', 'vim-plug'] }

" HTML, CSS, JavaScript, PHP, JSON, etc.
Plug 'https://gitcode.net/BlueSky4_19/vim-json.git'
Plug 'https://gitcode.net/BlueSky4_19/vim-css3-syntax.git'
Plug 'https://gitcode.net/BlueSky4_19/piv.git', { 'for' :['php', 'vim-plug'] }
Plug 'gko/vim-coloresque', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }
Plug 'pangloss/vim-javascript', { 'for' :['javascript', 'vim-plug'] }
"Plug 'https://gitcode.net/mirrors/mattn/emmet-vim.git'

" Python
" Plug 'vim-scripts/indentpython.vim'

" Markdown
" 会强制折叠，不好用
" Plug 'joker1007/vim-markdown-quote-syntax'
" markdown的高亮，可以设置代码块高亮，但似乎没必要
" Plug 'https://gitcode.net/mirrors/tpope/vim-markdown.git'
" Plug 'suan/vim-instant-markdown', {'for': 'markdown'}
" Plug 'instant-markdown/vim-instant-markdown', {'for': 'markdown'}
" Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install_sync() }, 'for' :['markdown', 'vim-plug'] }
Plug 'dhruvasagar/vim-table-mode', { 'on': 'TableModeToggle' }
" Plug 'vimwiki/vimwiki'

" Bookmarks
" Plug 'kshenoy/vim-signature'

" Go
Plug 'fatih/vim-go' , { 'for': ['go', 'vim-plug'], 'tag': '*' }

" Other useful utilities
"Plug 'terryma/vim-multiple-cursors'
Plug 'junegunn/goyo.vim' " distraction free writing mode
Plug 'https://gitcode.net/BlueSky4_19/limelight.vim'
Plug 'tpope/vim-surround' " type ysks' to wrap the word with '' or type cs'` to change 'word' to `word`
Plug 'godlygeek/tabular' " type ;Tabularize /= to align the =
Plug 'gcmt/wildfire.vim' " in Visual mode, type i' to select all text in '', or type i) i] i} ip
" Plug 'scrooloose/nerdcommenter' " in <space>cc to comment a line
" Plug 'ludovicchabant/vim-gutentags'
" Dependencies
Plug 'MarcWeber/vim-addon-mw-utils'
" Plug 'https://gitcode.net/mirrors/kana/vim-textobj-user.git'
" Plug 'fadein/vim-FIGlet'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
"Plug 'honza/vim-snippets'
Plug 'tpope/vim-commentary'

"snippet
" Plug 'SirVer/ultisnips'

call plug#end()

" let g:airline_powerline_fonts = 1
" let g:airline#extensions#tabline#enabled = 1

" comment tags
autocmd FileType vim setlocal commentstring=\"\ %s
autocmd FileType c,cpp,json setlocal commentstring=//\ %s
autocmd FileType py setlocal commentstring=\#\ %s
autocmd FileType markdown setlocal commentstring=<!--\ %s\-->
autocmd BufEnter,BufRead,BufNewFile *.Xmodmap* setlocal commentstring=\!\%s

try
    exec 'source ~/.config/nvim/coc.config.vim'
endtry

try
    let g:SnazzyTransparent = 1
    color snazzy
    " color monokai
catch
    color default
endtry


" 使用原生UltiSnips配置
" let g:UltiSnipsEditSplit="vertical"
" let g:UltiSnipsExpandTrigger=",s"
" nnoremap <nowait> <silent> <LEADER>sn :set splitright<CR>:UltiSnipsEdit<CR>
" inoremap ,s <C-R>=(Ulti_ExpandOrJump_and_getRes() > 0)?"":IMAP_Jumpfunc('', 0)<CR>
" let g:ulti_expand_or_jump_res = 0 "default value, just set once
" function! Ulti_ExpandOrJump_and_getRes()
"  call UltiSnips#ExpandSnippetOrJump()
"  return g:ulti_expand_or_jump_res
" endfunction

" ===
" === vim-instant-markdown
" ===
let g:instant_markdown_slow = 0
let g:instant_markdown_autostart = 0
" let g:instant_markdown_open_to_the_world = 1
" let g:instant_markdown_allow_unsafe_content = 1
" let g:instant_markdown_allow_external_content = 0
" let g:instant_markdown_mathjax = 1
let g:instant_markdown_autoscroll = 1
let g:instant_markdown_browser = "google-chrome-stable --new-window"

let g:vimwiki_list = [{'path': '~/vimwiki/',
\ 'syntax': 'markdown', 'ext': '.md'}]

" autopair
" let g:AutoPairsShortcutJump = '<M-i>'
let g:AutoPairsShortcutJump = '<M-0>'
let g:AutoPairsShortcutToggle = ''
let g:AutoPairsShortcutFastWrap = ''

" nerdtree {{{
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
" autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
"     \ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
" Exit Vim if NERDTree is the only window remaining in the only tab.
" autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Close the tab if NERDTree is the only window remaining in it.
" autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" nnoremap <A-1> :NERDTreeFocus<cr>
" autocmd VimEnter * NERDTree | wincmd p
" let g:NERDTreeMapCustomOpen      = get(g:, 'NERDTreeMapCustomOpen',      '<CR>')
" let g:NERDTreeMapActivateNode    = get(g:, 'NERDTreeMapActivateNode',    '<Right>')
" let g:NERDTreeMapChangeRoot      = get(g:, 'NERDTreeMapChangeRoot',      'C')
" let g:NERDTreeMapChdir           = get(g:, 'NERDTreeMapChdir',           'cd')
" let g:NERDTreeMapCloseChildren   = get(g:, 'NERDTreeMapCloseChildren',   'X')
" let g:NERDTreeMapCloseDir        = get(g:, 'NERDTreeMapCloseDir',        'x')
" let g:NERDTreeMapDeleteBookmark  = get(g:, 'NERDTreeMapDeleteBookmark',  'D')
" let g:NERDTreeMapMenu            = get(g:, 'NERDTreeMapMenu',            'm')
" let g:NERDTreeMapHelp            = get(g:, 'NERDTreeMapHelp',            '?')
" let g:NERDTreeMapJumpParent      = get(g:, 'NERDTreeMapJumpParent',      'p')
" let g:NERDTreeMapJumpRoot        = get(g:, 'NERDTreeMapJumpRoot',        'P')
" let g:NERDTreeMapOpenExpl        = get(g:, 'NERDTreeMapOpenExpl',        'j')
" let g:NERDTreeMapOpenInTab       = get(g:, 'NERDTreeMapOpenInTab',       'ta')
" let g:NERDTreeMapOpenInTabSilent = get(g:, 'NERDTreeMapOpenInTabSilent', 'T')
" let g:NERDTreeMapOpenRecursively = get(g:, 'NERDTreeMapOpenRecursively', '')
" let g:NERDTreeMapOpenSplit       = get(g:, 'NERDTreeMapOpenSplit',       '')
" let g:NERDTreeMapOpenVSplit      = get(g:, 'NERDTreeMapOpenVSplit',      's')
" let g:NERDTreeMapPreview         = get(g:, 'NERDTreeMapPreview',         'o'.NERDTreeMapActivateNode)
" let g:NERDTreeMapPreviewSplit    = get(g:, 'NERDTreeMapPreviewSplit',    ''.NERDTreeMapOpenSplit)
" let g:NERDTreeMapPreviewVSplit   = get(g:, 'NERDTreeMapPreviewVSplit',   ''.NERDTreeMapOpenVSplit)
" let g:NERDTreeMapQuit            = get(g:, 'NERDTreeMapQuit',            '<Esc>')
" let g:NERDTreeMapRefresh         = get(g:, 'NERDTreeMapRefresh',         'r')
" let g:NERDTreeMapRefreshRoot     = get(g:, 'NERDTreeMapRefreshRoot',     'R')
" let g:NERDTreeMapToggleBookmarks = get(g:, 'NERDTreeMapToggleBookmarks', 'm')
" let g:NERDTreeMapToggleFiles     = get(g:, 'NERDTreeMapToggleFiles',     '')
" let g:NERDTreeMapToggleFilters   = get(g:, 'NERDTreeMapToggleFilters',   '')
" let g:NERDTreeMapToggleHidden    = get(g:, 'NERDTreeMapToggleHidden',    'zo')
" let g:NERDTreeMapToggleZoom      = get(g:, 'NERDTreeMapToggleZoom',      '')
" let g:NERDTreeMapUpdir           = get(g:, 'NERDTreeMapUpdir',           '')
" let g:NERDTreeMapUpdirKeepOpen   = get(g:, 'NERDTreeMapUpdirKeepOpen',   '')
" let g:NERDTreeMapCWD             = get(g:, 'NERDTreeMapCWD',             '')
" let g:NERDTreeMenuDown           = get(g:, 'NERDTreeMenuDown',           'e')
" let g:NERDTreeMapJumpLastChild   = get(g:, 'NERDTreeMapJumpLastChild',   'E')
" let g:NERDTreeMapJumpNextSibling = get(g:, 'NERDTreeMapJumpNextSibling', '')
" let g:NERDTreeMenuUp             = get(g:, 'NERDTreeMenuUp',             'u')
" let g:NERDTreeMapJumpFirstChild  = get(g:, 'NERDTreeMapJumpFirstChild',  'U')
" let g:NERDTreeMapJumpPrevSibling = get(g:, 'NERDTreeMapJumpPrevSibling', '')
"}}}

" {{{ gutentags
" gutentags 搜索工程目录的标志，当前文件路径向上递归直到碰到这些文件/目录名
" let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']

" 所生成的数据文件的名称
" let g:gutentags_ctags_tagfile = '.tags'

" 同时开启 ctags 和 gtags 支持：
" let g:gutentags_modules = []
" if executable('ctags')
"     let g:gutentags_modules += ['ctags']
" endif
" if executable('gtags-cscope') && executable('gtags')
"     let g:gutentags_modules += ['gtags_cscope']
" endif

" 将自动生成的 ctags/gtags 文件全部放入 ~/.cache/tags 目录中，避免污染工程目录
" let g:gutentags_cache_dir = expand('~/.cache/tags')

" 配置 ctags 的参数，老的 Exuberant-ctags 不能有 --extra=+q，注意
" let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
" let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
" let g:gutentags_ctags_extra_args += ['--c-kinds=+px']

" 如果使用 universal ctags 需要增加下面一行，老的 Exuberant-ctags 不能加下一行
" let g:gutentags_ctags_extra_args += ['--output-format=e-ctags']

" 禁用 gutentags 自动加载 gtags 数据库的行为
" let g:gutentags_auto_add_gtags_cscope = 0
" }}}
"

" vimwiki
" omap ah <Plug>VimwikiTextObjHeader
" vmap ah <Plug>VimwikiTextObjHeaderV
" omap hh <Plug>VimwikiTextObjHeaderContent
" vmap hh <Plug>VimwikiTextObjHeaderContentV
" omap aH <Plug>VimwikiTextObjHeaderSub
" vmap aH <Plug>VimwikiTextObjHeaderSubV
" omap hH <Plug>VimwikiTextObjHeaderSubContent
" vmap hH <Plug>VimwikiTextObjHeaderSubContentV
" omap a\ <Plug>VimwikiTextObjTableCell
" vmap a\ <Plug>VimwikiTextObjTableCellV
" omap h\ <Plug>VimwikiTextObjTableCellInner
" vmap h\ <Plug>VimwikiTextObjTableCellInnerV
" omap ac <Plug>VimwikiTextObjColumn
" vmap ac <Plug>VimwikiTextObjColumnV
" omap hc <Plug>VimwikiTextObjColumnInner
" vmap hc <Plug>VimwikiTextObjColumnInnerV
" omap al <Plug>VimwikiTextObjListChildren
" vmap al <Plug>VimwikiTextObjListChildrenV
" omap hl <Plug>VimwikiTextObjListSingle
" vmap hl <Plug>VimwikiTextObjListSingleV

"markbar
nmap M <Plug>ToggleMarkbar
let g:markbar_next_mark_mapping = 'k'
let g:markbar_previous_mark_mapping = 'K'

" easymotion
let g:EasyMotion_do_mapping=0
map <nowait> s <Plug>(easymotion-s2)
let g:EasyMotion_inc_highlight= 1
let g:EasyMotion_landing_highlight = 0
let g:EasyMotion_smartcase = 1
let g:EasyMotion_verbose = 0
" let g:EasyMotion_off_screen_search = 0

" let g:LanguageClient_serverCommands = {
" \ 'Cpp': ['/usr/bin/clang']
" \  }
" vim-comment
nmap <M-n> gcce
vmap <M-n> gc

" vim-go
let g:go_echo_command_info = 0
let g:go_doc_keywordprg_enabled = 0
"vim-markdown-folding
"https://vimawesome.com/plugin/vim-markdown-folding
" set nocompatible
" if has("autocmd")
"   filetype plugin indent on
" endif
let g:airline#extensions#tagbar#enabled = 1

" ### oscyank ###
if exists('$SSH_CONNECTION')
    autocmd TextYankPost * if v:event.operator is 'y' && v:event.regname is '' | execute 'OSCYankReg "' | endif
endif

let g:vifm_help_mapping = ''

" goyo
let g:goyo_width=80
let g:goyo_height=85
let g:goyo_linenr=0

nnoremap zz :Goyo<cr>
function! s:goyo_enter()
    set number
    noremap <nowait> <LEADER>nn :Goyo<cr>:call Compile()<CR>
    noremap <LEADER>ne :Goyo<cr>:call CompileRun()<CR>
    noremap <LEADER>ee :Goyo<cr>:call ZzxRun()<CR>
    noremap <LEADER>en :Goyo<cr>:call ZzxRedirectRun()<CR>
    noremap <LEADER>hh :Goyo<cr>:call Debug()<CR>
    " Limelight
endfunction

function! s:goyo_leave()
    " Limelight!
    set cursorline
    noremap <nowait> <LEADER>nn :call Compile()<CR>
    noremap <LEADER>ne :call CompileRun()<CR>
    noremap <LEADER>ee :call ZzxRun()<CR>
    noremap <LEADER>en :call ZzxRedirectRun()<CR>
    noremap <LEADER>hh :call Debug()<CR>
endfunction

autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()

" limelight
" Color name (:help cterm-colors) or ANSI code
let g:limelight_conceal_ctermfg = 'gray'
let g:limelight_conceal_ctermfg = 240

" Color name (:help gui-colors) or RGB color
let g:limelight_conceal_guifg = 'DarkGray'
let g:limelight_conceal_guifg = '#777777'

" Default: 0.5
let g:limelight_default_coefficient = 0.7

" Number of preceding/following paragraphs to include (default: 0)
let g:limelight_paragraph_span = 1

" Beginning/end of paragraph
"   When there's no empty line between the paragraphs
"   and each paragraph starts with indentation
let g:limelight_bop = '^\s'
let g:limelight_eop = '\ze\n^\s'

" Highlighting priority (default: 10)
"   Set it to -1 not to overrule hlsearch
let g:limelight_priority = -1

" latex
let g:tex_flavor = 'latex'
let g:vimtex_quickfix_mode = 0
let g:vimtex_view_general_viewer = 'zathura'
let g:vimtex_view_method = 'zathura'
let g:vimtex_compiler_latexmk = {
            \ 'build_dir' : {-> 'out'},
            \ 'executable' : 'latexmk',
            \ 'options' : [
            \   '-xelatex',
            \   '-file-line-error',
            \   '-synctex=1',
            \   '-interaction=nonstopmode',
            \ ],
            \}
let g:vimtex_compiler_progname = 'nvr'	" 这一行默认就是这个值，但如果编译出现问题，可以手动指定试一试。
augroup vimtex_config
  autocmd!
  autocmd User VimtexEventQuit call vimtex#compiler#clean(0)
augroup END

" fcitx
" let g:fcitx5_remote = 1
"##### auto fcitx  ###########
" let g:input_toggle = 1
" function! Fcitx2en()
"    let s:input_status = system("fcitx-remote5")
"    if s:input_status == 2
"       let g:input_toggle = 1
"       let l:a = system("fcitx-remote5 -c")
"    endif
" endfunction

" function! Fcitx2zh()
"    let s:input_status = system("fcitx-remote5")
"    if s:input_status != 2 && g:input_toggle == 1
"       let l:a = system("fcitx-remote5 -o")
"       let g:input_toggle = 0
"    endif
" endfunction

" set ttimeoutlen=0
" Exit insert mode
 " autocmd InsertLeave * call Fcitx2en()
" Enter insert mode
 " autocmd InsertEnter * call Fcitx2zh()
"##### auto fcitx end ######

"
" let g:XkbSwitchEnabled = 1
" let g:XkbSwitchLib = '/usr/lib/libxkbswitch.so'
" let g:XkbSwitchNLayout = 'us'


if has('nvim')
    try
        exec 'luafile ~/.config/nvim/test.lua'
    endtry
endif

